package com.zhongyouyun.other.file;

import cn.hutool.setting.dialect.Props;
import cn.hutool.setting.dialect.PropsUtil;
import com.zhongyouyun.admin.model.FileModel;
import com.zhongyouyun.other.file.Bean.FileBean;
import com.zhongyouyun.other.file.Bean.FileBeanWork;
import com.zhongyouyun.other.file.abstractfactory.FileFactory;
import com.zhongyouyun.other.file.factory.AliFileFactory;
import com.zhongyouyun.other.file.factory.LocalFileFactory;
import com.zhongyouyun.utils.PropUtils;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

public class FileImp {
    public static FileBean ImpUploadFile() {
        return null;
    }

    public static FileBean ImpUploadFile(MultipartFile file) {
        Props props = PropUtils.get("properties/file");
        int FileSw = props.getInt("file.swich");
        FileFactory fileFactory = null;
        switch (FileSw) {
            case 1:
                fileFactory = new LocalFileFactory();
                return fileFactory.uploadFile(file);
            case 2:
                fileFactory = new AliFileFactory();
                return fileFactory.uploadFile(file);
            default:
                return null;
        }
    }




    public static String ImpUploadHtml(String html) {
        Props props = PropUtils.get("properties/file");
        int FileSw = props.getInt("file.swich");
        FileFactory fileFactory = null;
        switch (FileSw) {
            case 1:
                fileFactory = new LocalFileFactory();
                return fileFactory.uploadHtml(html);
            case 2:
                fileFactory = new AliFileFactory();
                return fileFactory.uploadHtml(html);
            default:
                return null;
        }

    }

    public static FileBeanWork ImpUploadhandleFile(List<MultipartFile> files) {
        Props props = PropUtils.get("properties/file");
        int FileSw = props.getInt("file.swich");
        FileFactory fileFactory = null;
        switch (FileSw) {
            case 1:
                fileFactory = new LocalFileFactory();
                return fileFactory.uploadhandleFile(files);
            case 2:
                fileFactory = new AliFileFactory();
                return fileFactory.uploadhandleFile(files);
            default:
                return null;
        }
    }

    public static void ImpdownloadFile(FileModel fileModel, HttpServletRequest request, HttpServletResponse response) {
        Props props = PropUtils.get("properties/file");
        int FileSw = props.getInt("file.swich");
        FileFactory fileFactory = null;
        switch (FileSw) {
            case 1:
                fileFactory = new LocalFileFactory();
                fileFactory.downloadFile(fileModel, request, response);
            case 2:
                fileFactory = new AliFileFactory();
                fileFactory.downloadFile(fileModel, request, response);
            default:
                ;
        }
    }

    public static FileBeanWork delFile(FileModel fileModel) {

        Props props = PropUtils.get("properties/file");
        int FileSw = props.getInt("file.swich");
        FileFactory fileFactory = null;
        switch (FileSw) {
            case 1:
                fileFactory = new LocalFileFactory();
                return fileFactory.delFile(fileModel);
            case 2:
                fileFactory = new AliFileFactory();
                return fileFactory.delFile(fileModel);
            default:
                return null;
        }

    }

    public static Boolean deleteHtml(List<String> list) {
        Boolean flag = false;
        Props props = PropUtils.get("properties/file");
        int FileSw = props.getInt("file.swich");
        FileFactory fileFactory = null;
        switch (FileSw) {
            case 1:
                fileFactory = new LocalFileFactory();
                flag = fileFactory.deleteHtml(list);
            case 2:
                fileFactory = new AliFileFactory();
                flag = fileFactory.deleteHtml(list);
            default:
                flag = false;
        }
        return flag;
    }
}
